using System.Collections;
using UnityEngine;

public class SlowMotionIntro : MonoBehaviour
{
	public static SlowMotionIntro Instance;

	public bool slow;

	public float duration;

	public float magnitude;

	public PanelAnimator anim;

	private bool locked;

	private void Start()
	{
		Instance = this;
		slow = false;
	}

	private void Update()
	{
		if (!BadLogic.pause)
		{
			if (slow)
			{
				Time.timeScale = 0.002f;
				Time.fixedDeltaTime = Time.deltaTime * 0.02f;
			}
			else if (!locked)
			{
				Time.timeScale = 1f;
			}
			else
			{
				Time.timeScale = 0.001f;
				Time.fixedDeltaTime = Time.deltaTime * 0.02f;
			}
		}
	}

	public void startSlow()
	{
		if (!locked)
		{
			locked = true;
			Shake();
			anim.show();
		}
	}

	private IEnumerator delay()
	{
		yield return new WaitForSecondsRealtime(duration);
		if (!slow)
		{
			slow = true;
		}
	}

	private IEnumerator Shake()
	{
		float elapsed = 0f;
		Vector3 originalCamPos = Camera.main.transform.position;
		while (elapsed < duration)
		{
			elapsed += Time.deltaTime;
			float num = elapsed / duration;
			float num2 = 1f - Mathf.Clamp(4f * num - 3f, 0f, 1f);
			float num3 = UnityEngine.Random.value * 2f - 1f;
			float num4 = UnityEngine.Random.value * 2f - 1f;
			num3 *= magnitude * num2;
			num4 *= magnitude * num2;
			Camera.main.transform.position = new Vector3(num3, num4, originalCamPos.z);
			yield return null;
		}
		Camera.main.transform.position = originalCamPos;
	}
}
